//
//  ZQBaseNavigationController.swift
//  Timor微博
//
//  Created by 周周旗 on 2019/2/26.
//  Copyright © 2019 ZQ. All rights reserved.
//

import UIKit

class ZQBaseNavigationController: UINavigationController {    
    override func viewDidLoad() {
        super.viewDidLoad()
        
       //隐藏系统自带的`navigationBar`
        navigationBar.isHidden = true
    }
    
    ///重写push方法，控制`hidesBottomBarWhenPushed`
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if children.count > 0 {
            viewController.hidesBottomBarWhenPushed = true
            
            //判断 控制器的类型 if let  as?
            if let vc = viewController as? ZQBaseViewController{
                
                var title = "返回"
                if (vc.children.count == 1){
                    title = vc.children.first?.title ?? "返回"
                }
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToPresent), isBackItem: true)
            }
        }
        super.pushViewController(viewController, animated: true)
    }
    
   @objc private func popToPresent(){
        popViewController(animated: true)
    }
}
